<template>
	<view>
		<!-- <button type="default" @click="login">login</button> -->
		<u-empty v-if="list.length==0"></u-empty>
		<view class="u-border-top" v-else>
			<view class="list">
				<view class="item u-border-bottom" v-for="item in list" :key='item.id' @click="handleNavTo(item)">
					<view class="item_img_mg">
						<image class="img" :src="item.imgUrl" mode=""></image>
						<!-- //1 语音消息 2 图片消息（包含表情包） 3 表情 4 文字消息 -->
						<view class="msg_box">
							<view class="title">
								{{item.name}}
							</view>
							<view class="summary" v-if="item.msgType==2">
								[图片]
							</view>
							<view class="summary" v-if="item.msgType==1">
								[语音]
							</view>
							<view class="summary" v-if="item.msgType==4">
								{{item.msg}}
							</view>
							<view class="summary" v-if="item.msgType==3">
								{{item.msg}}
							</view>
							<view class="summary" v-if="item.msgType==8">
								[商品]
							</view>
						</view>
					</view>
					<view class="time">
						{{$u.timeFormat(item.time, 'yyyy年mm月dd日') }}
					</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		onShow() {
			this.init()
			this.createSetInterval()
		},
		data() {
			return {
				list: []
			};
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.init()
		},
		// 离开页面销毁轮询器
		destroyed() {
			this.stopSetInterval();
			innerAudioContext.stop()
			innerAudioContext.destroy()
		},
		mounted() {
			
			// console.log(uni.$TUIKit, '===<<<<<')

		},
		methods: {
			// login() {
			// 	let promise = uni.$TUIKit.login({
			// 		userID: 'your userID',
			// 		userSig: '9a98cd0ce9ea6ac20783d8555b5dabcd71045b5a320ef2334c64a757b7aac5ef'
			// 	});
			// 	promise.then(function(imResponse) {
			// 		console.log(imResponse.data); // 登录成功
			// 		if (imResponse.data.repeatLogin === true) {
			// 			// 标识账号已登录，本次登录操作为重复登录。v2.5.1 起支持
			// 			console.log(imResponse.data.errorInfo);
			// 		}
			// 	}).catch(function(imError) {
			// 		console.warn('login error:', imError); // 登录失败的相关信息
			// 	});
			// },
			// 关闭轮询
			stopSetInterval() {
				if (this.timer) {
					clearInterval(this.timer);
					this.timer = null;
				}
			},
			createSetInterval() {
				this.stopSetInterval();
				let _this = this;
				this.timer = setInterval(() => {
					_this.init();
				}, 2000);
			},
			handleNavTo(item) {
				uni.navigateTo({
					url: '/pages/chat/chat?userId=' + item.id + '&audioName=' + item.name
				})
			},
			init() {
				this.$u.api.findMsgUserList().then(res => {
					console.log(res, '列表')
					this.list = res
					uni.stopPullDownRefresh();
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.list {


		.item {
			padding: 24rpx;
			width: 100%;
			display: flex;
			justify-content: space-between;

			.time {
				font-size: 24rpx;
				color: #ACACAC;
			}

			.item_img_mg {
				display: flex;

				.msg_box {
					height: 100rpx;
					display: flex;
					justify-content: space-between;
					flex-direction: column;

					.summary {
						color: #A2A2A2;
						font-size: 24rpx;

					}

					.title {
						font-size: 32rpx;
						color: #101010;
					}
				}

				.img {
					width: 100rpx;
					height: 100rpx;
					border-radius: 50%;
					margin-right: 24rpx;
				}
			}
		}
	}
</style>
